#!/bin/sh

BINARY_PATH=./src/gmediarender
XMLPATH=/etc/config/gmediarender.xml
IFNAME="enp0s8"
UUID=$(openssl rand -hex 6)
XMLCONTENT="<?xml version=\"1.0\"?> \n<Gmediarender>\n<Group>\n<GroupID>$UUID</GroupID>\n<GroupRole>Signle</GroupRole>\n</Group>\n</Gmediarender>"
if [ ! -f $XMLPATH ]
	then
	echo "$XMLCONTENT" > $XMLPATH
fi

GROUP_ROLE=$(sed -n 's/.*>\(.*\)<\/GroupRole>/\1/p' $XMLPATH)
IPADDR=$(ip addr show $IFNAME | grep 'inet ' | awk  '{print $2}' | sed 's/\/.*//g')
DEVICE_NAME="MuiltSpeaker_"$GROUP_ROLE"_"$UUID

#echo $UUID
echo $IPADDR
echo $DEVICE_NAME
echo $GROUP_ROLE

$BINARY_PATH -u "$UUID" -I "$IPADDR" -f "$DEVICE_NAME" --logfile=/dev/stdout
